<template>
  <el-dialog
    v-model="dialogFormVisible"
    title="查看详情"
    width="800"
    :close-on-click-modal="false"
  >
    <el-form :model="form">
      <el-form-item
        label="姓名："
        :label-width="formLabelWidth"
        style="margin-top: 20px"
      >
        <span>{{ form.name }}</span>
      </el-form-item>
      <el-form-item label="手机号：" :label-width="formLabelWidth">
        <span>{{ form.phone }}</span>
      </el-form-item>
      <el-form-item label="处理状态" :label-width="formLabelWidth">
        <el-radio-group v-model="form.status">
          <el-radio value="1" size="large" :disabled="disabled">
            已处理
          </el-radio>
          <el-radio value="2" size="large" :disabled="disabled">
            未处理
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="处理备注" :label-width="formLabelWidth">
        <el-input
          v-model="form.remark"
          autocomplete="off"
          :disabled="disabled"
        />
      </el-form-item>
    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitEvent" :disabled="disabled">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref } from 'vue';
import { getCooperateSave } from '@/api/operation/operation.js';
import { ElMessage } from 'element-plus';
const emit = defineEmits(['refreshList']);

const dialogFormVisible = ref(false);
const formLabelWidth = '140px';

const form = ref();
const disabled = ref(false);

// 打开弹窗
const openChange = (val) => {
  form.value = val;
  form.value.status = form.value.status.toString();
  if (form.value.status === '2') {
    disabled.value = true;
  } else {
    disabled.value = false;
  }
  dialogFormVisible.value = true;
};

// 提交按钮
const submitEvent = () => {
  console.log('form:', form.value);
  dialogFormVisible.value = false;
  getCooperateSave({
    id: form.value.id,
    status: form.value.status,
    remark: form.value.remark,
  }).then((res) => {
    console.log('res:', res);
    if (res.code === 20000) {
      ElMessage({
        message: '提交成功',
        type: 'success',
      });
      emit('refreshList');
    } else {
      ElMessage({
        message: '提交失败',
        type: 'error',
      });
    }
  });
};

defineExpose({
  openChange,
});
</script>

<style lang="scss" scoped>
.demo-image__preview {
  padding: 10px;
}
</style>
